#include "client.h"
#include "clientwaitpool.h"
#include "../session/session.h"
#include <iostream>
#include <sstream>

Client::Client(unsigned int request_id, Session *session)
{
    m_requestID = request_id;
    m_session = session;
}

Client::~Client()
{
}

void Client::sendRequest(const std::string name,
                        const std::string content_type,
                        unsigned long long content_length,
                        const void *data )
{
    std::string id;
    std::stringstream ss(id);
    ss << m_requestID;
    std::string service_name = name + "::" + ss.str();
    ClientWaitPool::getInstance()->addWaitClient(this);
    m_session->sendServiceRequest(service_name, content_type, content_length, data);
}


void Client::responseReceived(const std::string name,
                    const std::string content_type,
                    unsigned long long content_length,
                    const void *data)
{
    ClientWaitPool::getInstance()->removeWaitClient(m_requestID);
    printf("++++++Respone received::+++++++++\n name: %s \n content_type: %s \n content %s \n",
                            name.c_str(), content_type.c_str(), (char*)data );
}
